import Vue from 'vue'
import PdfView from './PdfView'

function blobToArrayBuffer(blob) {
  return new Promise((resolve, reject) => {
    const reader = new FileReader()
    reader.onloadend = () => {
      resolve(reader.result)
    }
    reader.readAsArrayBuffer(blob)
  })
}

export default async function renderPdf(blob, target) {
  const buffer = await blobToArrayBuffer(blob)
  console.log(buffer)
  return new Vue({
    render: h => h(PdfView, { props: { data: buffer }})
  }).$mount(target)
}
